﻿//定义常量
function getHost() {
	var HOST_BUSINESS_DEVOLP = "http://59.46.97.115:8071/hyapipro/hongyan"; //开发环境地址
	var HOST_BUSINESS_RELEASE = "http://itg.sih.cq.cn:18080/api/hongyan"; //线上环境基地址
	var HOST_BUSINESS_TEST = "http://sy.aerozhonghuan.com/test/sih/api/hongyan"; //公网测试环境基地址
	var HOST_BUSINESS_UAT = "http://uat.tls.sih.cq.cn:8000/api/hongyan"; //公网测试环境基地址

	var host = HOST_BUSINESS_TEST;
	if(typeof __buildConfig != "undefined") { //尝试从自动生成的配置文件中读取 服务器地址url
		host = __buildConfig["HOST_BUSINESS"];
		console.log("尝试从自动生成的配置文件中读取 服务器地址url = " + host);
	}
	return host;
}

//获取url中参数
function getparms() {
	var str = window.location.href;
	var num = str.indexOf("?");
	str = str.substr(num + 1);
	var arr = str.split("&");
	var dictArr = {};

	var k;
	var v;
	for(var i = 0; i < arr.length; i++) {
		num = arr[i].indexOf("=");
		if(num <= 0) continue;
		k = arr[i].substr(0, (num));
		v = arr[i].substr(num + 1);
		dictArr[k] = v;
	}
	return dictArr;
}

//加密处理
function makeSign(terminalId, timestap) {
	if(typeof(terminalId) == "undefined")
		return null;
	if(typeof(timestap) == "undefined")
		return null;
	var sign = md5("hong" + terminalId + timestap + "yan");
	return typeof(sign) == "undefined" ? null : sign.toUpperCase();
}

//loading
function loadingFn() {
	console.log("点击月flag_list_state=====" + flag_list_state);
	console.log("点击月flag_chart_state====" + flag_chart_state);
	if((flag_list_state == false) && (flag_chart_state == false)) {

		$(".loading-gif-section").hide();

	} else if((flag_list_state == true) || (flag_chart_state == true)) {
		$(".loading-gif-section").css({
			"background": "#000",
			"opacity": ".6"
		}).show();

	}
}

//ajax请求  post请求
function ajaxJson(url, json_data, fn) {
	var json_str = JSON.stringify(json_data);
	console.log("发送请求url=" + url)
	$.ajax({
		type: "post",
		url: url,
		dateType: "json",
		data: json_str,
		contentType: "application/json",
		success: fn,
		erro: function() {
			alert("请求失败");
		}
	});
}

//get请求
function ajaxJsonGet(url, fn) {
	console.log("get请求函数" + url);
	$.ajax({
		type: "get",
		url: url,
		async: true,
		success: fn,
		erro: function(err) {
			alert("请求失败");
		}
	});
}
//获取时间
function getTripTime(time, className) {
	var s = Math.round(time / 1000);
	var h = parseInt(s / 3600);
	var m = Math.round((s / 3600 - h) * 60);
	var str = h + ":" + m;
	$(className).text(str);
	return str;
}

function getTime(time, className) {
	var newTime = new Date(time);
	var nowTime = new Date();

	var year = newTime.getFullYear();
	var month = newTime.getMonth() + 1;
	var day = newTime.getDate();

	var now_year = nowTime.getFullYear();
	var now_month = nowTime.getMonth() + 1;
	var now_day = nowTime.getDate();

	var h = newTime.getHours();
	var m = newTime.getMinutes();
	var s = newTime.getSeconds();
	month = month < 10 ? "0" + month : month;
	day = day < 10 ? "0" + day : day;
	h = h < 10 ? "0" + h : h;
	m = m < 10 ? "0" + m : m;
	s = s < 10 ? "0" + s : s;
	var str;
	if((year == now_year)) {
		str = month + "-" + day + " " + h + ":" + m;
		if((year == now_year) && (month == now_month) && (day == now_day)) {

			str = "今天  " + h + ":" + m;
		}
	} else {
		str = year + "-" + month + "-" + day + " " + h + ":" + m;
	}

	$(className).text(str);
	return str;
}
//获取当天时间
function getDayTime(time) {
	var newTime = new Date(time);
	//var newTime = new Date();
	var year = newTime.getFullYear();
	var month = newTime.getMonth() + 1;
	var day = newTime.getDate();
	var h = newTime.getHours();
	var m = newTime.getMinutes();
	var s = newTime.getSeconds();
	month = month < 10 ? "0" + month : month;
	day = day < 10 ? "0" + day : day;
	h = h < 10 ? "0" + h : h;
	m = m < 10 ? "0" + m : m;
	s = s < 10 ? "0" + s : s;
	var str = h + ":" + m + ":" + s;
	return str;
}